﻿namespace CoreLibrary.Email {

    public class EmailRequestBuilder {

        private readonly SendEmailRequest _request = new SendEmailRequest();
        
        public SendEmailRequest Build() {
            Asserts.NotNull (_request.From,       "From Email Address can not be null.");
            Asserts.NotBlank(_request.From.Email, "From Email address is blank");
            Asserts.NotEmpty(_request.To,         "Email recipient is empty.");
            return _request;
        }

        public EmailRequestBuilder SetFrom(string name, string address) {
            _request.From = new EmailAddress(name, address);
            return this;
        }

        public EmailRequestBuilder AddTo(EmailAddress to) {
            _request.To.Add(to);
            return this;
        }

        public EmailRequestBuilder AddCc(EmailAddress cc) {
            _request.Cc.Add(cc);
            return this;
        }

        public EmailRequestBuilder AddBcc(EmailAddress bcc) {
            _request.Bcc.Add(bcc);
            return this;
        }

        public EmailRequestBuilder SetReplyTo(EmailAddress replyTo) {
            _request.ReplyTo = replyTo;
            return this;
        }

        public EmailRequestBuilder SetSubject(string subject) {
            _request.Subject = Util.GetString(subject);
            return this;
        }

        public EmailRequestBuilder SetHtmlContent(string htmlContent) {
            _request.HtmlBody = Util.GetString(htmlContent);
            return this;
        }

        public EmailRequestBuilder SetTextContent(string textContent) {
            _request.TextBody = textContent;
            return this;
        }

    }
}